<?php

namespace App\Admin\Controllers;

use App\MessageCode;
use App\SenderConfig;

use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Layout\Content;
use App\Http\Controllers\Controller;
use Encore\Admin\Controllers\ModelForm;
use Illuminate\Support\MessageBag;

class SendConfigController extends Controller
{
    use ModelForm;

    /**
     * Index interface.
     *
     * @return Content
     */
    public function index()
    {
        return Admin::content(function (Content $content) {

            $content->header('发货人地址设置');
            $content->description('发货人地址设置');

            $content->body($this->grid());
        });
    }

    /**
     * Edit interface.
     *
     * @param $id
     * @return Content
     */
    public function edit($id)
    {
        return Admin::content(function (Content $content) use ($id) {

            $content->header('发货人地址设置');
            $content->description('制作电子面单需要填写');

            $content->body($this->form()->edit($id));
        });
    }

    /**
     * Create interface.
     *
     * @return Content
     */
    public function create()
    {
        return Admin::content(function (Content $content) {

            $content->header('header');
            $content->description('description');

            $content->body($this->form());
        });
    }

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Admin::grid(SenderConfig::class, function (Grid $grid) {

        $grid->id('Id');


        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Admin::form(SenderConfig::class, function (Form $form) {
            $form->text('name','发货人姓名')->rules('required',[
                'required'=>'发货人姓名不能为空'
            ]);
            $form->text('company','公司名称');
            $form->text('city','行政区域划分')->help('严格按照国家行政区划，省市区三级， 逗号分隔。示例上海市,上海市,青浦区');
            $form->text('address','地址')->help('需要将省市区划信息加上，例如:上 海市,上海市,青浦区盈港东路 7766 号')->rules('required',[
                'required'=>'地址不能为空'
            ]);
            $form->text('postcode','邮编');
            $form->text('mobile','电话号码')->rules('required',[
                'required'=>'电话号码不能为空',
            ]);
            $form->saved(function ($form) {

                $success = new MessageBag([
                    'title'   => '保存成功',
                    'message' => '保存成功',
                ]);

                return back()->with(compact('success'));
            });

            $form->tools(function (Form\Tools $tools) {

                // 去掉返回按钮
                $tools->disableBackButton();

                // 去掉跳转列表按钮
                $tools->disableListButton();


            });
        });
    }
}
